# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import pymysql

class ProxyPipeline(object):
	def process_item(self, item, spider):
		db = pymysql.connect("localhost","root","123456","demo" )
		cursor = db.cursor()
		sql = "insert into IPProxy(country,ip_address,port,server_address,anonymous,type,check_datatime) values('%s','%s','%s','%s','高匿','%s',now())" %('中国',item['ip'],item['port'],item['position'],item['type'])
		print(sql)
		try:
			# 执行sql语句
			cursor.execute(sql)
			# 执行sql语句
			db.commit()
		except:
			# 发生错误时回滚
			db.rollback()
		# 关闭数据库连接
		db.close()
		return item
